

package com.hazelcast.config.vector;


import com.hazelcast.spi.annotation.Beta;

/**
 * Vector similarity metrics: These are utilized in search algorithms
 * to retrieve the top K most similar vectors to a target vector.
 * This labels describes the methodology employed during indexing and searching
 * of vectors to identify the nearest neighbors.
 *
 * @since 5.5
 */

@Beta
public enum Metric {

    /**
     * Euclidean distance
     */
    EUCLIDEAN(0),
    /**
     * Cosine distance
     */
    COSINE(1),
    /**
     * Dot product
     */
    DOT(2);

    private final int id;

    Metric(int id) {
        this.id = id;
    }

    /**
     * Returns the Metric as an enum.
     *
     * @return the Metric as an enum
     */
    public static Metric getById(final int id) {
        for (Metric type : values()) {
            if (type.id == id) {
                return type;
            }
        }
        throw new IllegalArgumentException("No metric is found for the given id.");
    }

    /**
     * Gets the ID for the given {@link Metric}.
     *
     * @return the ID
     */
    public int getId() {
        return id;
    }
}
